package com.wmjsoft.cglib

import net.sf.cglib.proxy.Enhancer
import net.sf.cglib.proxy.InvocationHandler
import org.junit.Assert
import java.lang.reflect.Method

fun main() {
    val enhancer = Enhancer()
    enhancer.setSuperclass(Test::class.java)
    enhancer.setCallback(object : InvocationHandler {
        @Throws(Throwable::class)
        override operator fun invoke(proxy: Any?, method: Method, args: Array<Any?>?): Any? {
            val a = method.declaringClass
            val b = method.returnType
            method.invoke(a,args)
            return null
        }
    })
    val proxy: Test = enhancer.create() as Test
    Assert.assertEquals("void", proxy.say())
    Assert.assertNotEquals("Hello cglib", proxy.toString())
}